﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Entity;
using Utils.DC.Web.UI;

public partial class Admin_Pages_CustomerEdit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["login"] != null)
            {
                lblUser.Text = Request.Params["username"];
                if (Convert.ToBoolean(Request.Params["active"]))
                {
                    chkActive.Checked = true;
                }
                else
                {
                    chkActive.Checked = false;
                }
            }
            else
            {
                Response.Redirect("../Login.aspx");
            }
            
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        int cusid = Convert.ToInt32(Request.Params["cusid"]);

        CustomerUI customerUI = new CustomerUI();
        int result = customerUI.Edit(cusid, Security.Encrypt(txtRePass.Text.Trim()));
        if (result > 0)
        {
            Response.Write("<script>alert('Edit successful'); window.location='../Pages/CustomerList.aspx';</script>");
        }
        else
        {
            Response.Write("<script>alert('Edit fail');</script>");
        }
    }
    protected void btnChangeActive_Click(object sender, EventArgs e)
    {
        int cusid = Convert.ToInt32(Request.Params["cusid"]);
        bool active = false;
        if (chkActive.Checked)
        {
            active = true;
        }
        else
        {
            active = false;
        }

        CustomerUI customerUI = new CustomerUI();
        int result = customerUI.Active(cusid, active);
        if (result > 0)
        {
            Response.Write("<script>alert('change active successful'); window.location='../Pages/CustomerList.aspx';</script>");
        }
        else
        {
            Response.Write("<script>alert('change active fail');</script>");
        }
    }
}
